import Vue from 'vue'
import App from './App.vue'
import router from './router'

import 'font-awesome/css/font-awesome.min.css'
import axios from 'axios'
// import qs from 'qs'
import {
    getCurDate,
    setSessionStorage,
    getSessionStorage,
    removeSessionStorage,
    setLocalStorage,
    getLocalStorage,
    removeLocalStorage,
    alert_res,
    alert_msg,
    ajax_
} from './common.js'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'


Vue.use(ElementUI)
Vue.config.productionTip = false

//设置axios的基础url部分
axios.defaults.baseURL = 'http://39.101.142.204:10086/';
// axios.defaults.baseURL = 'http://10.23.88.148:10086/';
//将axios挂载到vue实例上，使用时就可以 this.$axios 这样使用了
Vue.prototype.$axios = axios;

// Vue.prototype.$qs = qs;
//发送post请求
Vue.prototype.$ajax_ = ajax_;
// Vue.prototype.$message = Message
//弹出结果 自动解析 弹出请求结果
Vue.prototype.$alert_res = alert_res;
//主动弹出 信息窗口  -> 替换丑陋的alert
Vue.prototype.$alert_msg = alert_msg;
Vue.prototype.$getCurDate = getCurDate; //获取当前时间
Vue.prototype.$setSessionStorage = setSessionStorage;
Vue.prototype.$getSessionStorage = getSessionStorage;
Vue.prototype.$removeSessionStorage = removeSessionStorage;
Vue.prototype.$setLocalStorage = setLocalStorage;
Vue.prototype.$getLocalStorage = getLocalStorage;
Vue.prototype.$removeLocalStorage = removeLocalStorage;

router.beforeEach(function (to, from, next) {
    let user = sessionStorage.getItem('user');
    //除了登录、注册、首页、商家列表、商家信息之外，都需要判断是否登录
    if (!(to.path == '/' || to.path == '/index' || to.path == '/businessList' || to.path == '/businessInfo' || to.path == '/login' || to.path == '/register')) {
        if (user == null) {
            router.push('/login');
            // location.reload();
        }
    }
    next();
});

new Vue({
    router,
    render: h => h(App)
}).$mount('#app')
